/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.switz.agendacita.persistence;

import com.switz.agendacita.persistence.iface.RecordatorioAlarmaDao;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author tey
 */
@Repository
public class RecordatorioAlarmaDaoImpl extends JdbcDaoSupport implements RecordatorioAlarmaDao{

    
    @Autowired
    public RecordatorioAlarmaDaoImpl(DataSource dataSource) {

        setDataSource(dataSource);
    }

    @Override
    public void insertAlarmas(List alarmasLis) {
      SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(
                getJdbcTemplate().getDataSource())
                .withTableName("recordatorioalarmas");

        SqlParameterSource[] array = new SqlParameterSource[alarmasLis.size()];

        for (int i = 0; i < alarmasLis.size(); i++) {

            SqlParameterSource parameters = new BeanPropertySqlParameterSource(alarmasLis.get(i));
            array[i] = parameters;

        }

        simpleJdbcInsert.executeBatch(array);
    }

    @Override
    public void deleteAlarmas(int idRecordatorio) {
         String query = "delete from recordatorioalarmas where idrecordatorio = ?";
        getJdbcTemplate().update(query, new Object[]{idRecordatorio});
        System.out.println(idRecordatorio);
    }
    
}
